﻿using WindowsForms.AOnline.Model.BusinessObjects.Dictionary;
using WindowsForms.AOnline.Presenter.Dictionary.Account;
using WindowsForms.AOnline.View.Dictionary;
//using System.Threading.Tasks;

namespace WindowsForms.AOnline.Presenter.Dictionary.Stock
{
    public class StockPresenter : Presenter<IStockView>  
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="AccountPresenter" /> class.
        /// </summary>
        /// <param name="view">The view.</param>
        public StockPresenter(IStockView view)
            : base(view)
        {
        }

        /// <summary>
        /// Displays the specified employ identifier.
        /// </summary>
        /// <param name="stockId">The employ identifier.</param>
        public void Display(string stockId) 
        {
            if (stockId == null) { View.StockId = 0; return; }
            var obj = Model.GetStock(int.Parse(stockId));
            View.StockId = obj.StockId;
            View.StockCode = obj.StockCode;
            View.StockName = obj.StockName;
            View.Description = obj.Description;
            View.IsActive = obj.IsActive;
        }

        /// <summary>
        /// Saves this instance.
        /// </summary>
        /// <returns>System.Int32.</returns>
        public string Save()
        {
            var obj = new StockModel
            {
                StockId = View.StockId,
                StockCode = View.StockCode,
                StockName = View.StockName,
                Description = View.Description,
                IsActive = View.IsActive
            };
            return View.StockId == 0 ? Model.AddStock(obj) : Model.UpdateStock(obj);
        }

        /// <summary>
        /// Deletes the specified employ identifier.
        /// </summary>
        /// <param name="stockId">The employ identifier.</param>
        /// <returns>System.Int32.</returns>
        public string Delete(int stockId) 
        {
            return Model.DeleteStock(stockId);
        }
    }
}
